package Udp;


import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;

public class udp02 {
    public static void main(String[] args) throws IOException {
        DatagramSocket socket=new DatagramSocket(9999);
        byte[] bytes=new byte[1024];

        DatagramPacket packet=new DatagramPacket(bytes,bytes.length);
        System.out.println("等待接收");
        socket.receive(packet);
        int paccketlenght=packet.getLength();//接收到的实际长度
        bytes= packet.getData();//接收的数据
        String str=new String(bytes,0,paccketlenght);
        System.out.println(str);


        byte[] bytes1="肘".getBytes();
        DatagramPacket packet1=
                new DatagramPacket(bytes1,bytes1.length, InetAddress.getByName("192.168.43.97"),9998);
        socket.send(packet1);
        System.out.println("端口B结束");
        socket.close();
    }
}
